<%@ page import="org.springframework.web.context.request.SessionScope" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%request.setAttribute("ctx", request.getContextPath());%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui-v2.9.14/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui_ext/xmSelect/xm-select.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/crypto-js.js"></script>
    <title>用户列表</title>
</head>
<body>

<table class="layui-hide" id="ID-table-demo-search"></table>
<script>
    layui.use(function(){
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/user/list.do', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                {field:'id', title: 'ID', width:80, sort: true, fixed: true},
                {field:'username', title: '用户名',},
                {field:'roleName', title: '角色',},
                {field:'phone', title: '手机号'},
                {field:'email', title: '邮箱'},
                {field:'createTime', title: '创建时间'},
                {field:'lastLogin', title:'最后登录'}
            ]],
            parseData:function (res) {
                return{
                    code:res.code,
                    data:res.data.list,
                    count:res.data.total,
                }
            },
            limit:3,
            page: true,
            height: 310
        });
        // 日期
        laydate.render({
            elem: '.demo-table-search-date'
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function(data){
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            layer.msg('搜索成功');
            return false; // 阻止默认 form 跳转
        });
    });
</script>

</body>
</html>